home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Check if a file exists?
- Date: Thu, 18 Apr 96 12:59:33 GMT
- Organization: none
- Message-ID: <829832373snz@genesis.demon.co.uk>
- References: <4kp7pg$upe@news-s01.ny.us.ibm.net> <317261E6.31D0@spectratek.co.uk> <829569968snz@genesis.demon.co.uk> <3172B2E8.7D70@willows.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <3172B2E8.7D70@willows.com>
- tarang@willows.com "Tarang Deshpande" writes:
-
- >Lawrence Kirby wrote:
- >>
- >> In article <317261E6.31D0@spectratek.co.uk>
- >> dean_darlison@spectratek.co.uk "Dean Darlison" writes:
- >>
- >> >man access
- >>
- >> If that works on your system then the contents should tell you that this
- >> function is inappropriate for the question asked.
-
- >Under SUNOS 5.4, LINUX 1.1.46 and conforming to SVID, AT&T, POSIX,
- >X/OPEN, and BSD 4.3
- >
- >#include <unistd.h>
- >int access (const char *path, int amode)
- >
- >where amode is F_OK then the function is used to test for existance.
-
- Your man page should also have told you that access tests for accessibility
- (rather than existence) of the file against real UID and GID instead of the
- usual effective UID and GID which makes it inappropriate for almost all uses.
- Donald Lewine says it well (POSIX Programmer's Guide):
-
- "access() uses the real UID, not the effective UID. It is not a general
- utility for finding out "Can I do this?" before doing a call. It is used by
- SETUID programs to check their actions"
-
- As I said previously, use stat().
-
- For non-Unix/POSIX systems that implement an access() call it is worth
- knowing that your usage of access() may not be as portable as you think.
-
- Apologies for the off-topic posts but I hate to see bad advice left
- unchallenged.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-